﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using MvvmTreeView;

namespace System.Windows.Controls
{
    public static class Extensions
    {
        private static TreeNodeItemContent FindContent(FrameworkElement obj)
        {
            TreeNodeItemContent result = null;

            if (obj != null)
            {
                result = obj as TreeNodeItemContent;

                if (result == null)
                {
                    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
                    {
                        var child = VisualTreeHelper.GetChild(obj, i) as FrameworkElement;

                        result = FindContent(child);

                        if (result != null)
                        {
                            break;
                        }
                    }
                }
            }

            return result;
        }

        public static TreeNodeItemContent GetContent(this TreeViewItem item)
        {
            TreeNodeItemContent content = FindContent(item);

            return content;
        }
    }
}
